package a3_p04_jw_kw.junit;

import static org.junit.Assert.*;

import java.util.ArrayList;
import java.util.HashMap;

import org.jgrapht.Graph;
import org.jgrapht.graph.DefaultWeightedEdge;
import org.jgrapht.graph.DirectedPseudograph;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

import a1_p04_jw_kw.graph.GraphCreater;
import a1_p04_jw_kw.graph.GraphParser;
import a1_p04_jw_kw.struct.Node;
import a2_p04_jw_kw.graph.GraphNCreater;
import a2_p04_jw_kw.searchalgo.AStar;
import a2_p04_jw_kw.searchalgo.Dijkstra;
import a3_p04_jw_kw.spanningtree.Kruska;
import a3_p04_jw_kw.spanningtree.Prim;
import a3_p04_jw_kw.spanningtree.PrimFibonacciJGraphT;

public class SpanningTreeTest {
	
	Graph<Node, DefaultWeightedEdge> g;
	Graph<Node, DefaultWeightedEdge> g20;
	GraphNCreater creater;
	HashMap<String, ArrayList<Node>> bestWayMap = new HashMap<String, ArrayList<Node>>();

	public SpanningTreeTest() {
		this.g = null;
		this.g20 = null;
		this.creater = null;
	}

	@BeforeClass
	public static void setUpBeforeClass() throws Exception {
	}

	@AfterClass
	public static void tearDownAfterClass() throws Exception {
	}

	@Before
	public void setUp() throws Exception {
		setupGraphG4();

	}

	@After
	public void tearDown() throws Exception {
	}
	
	@Test
	public void testinit(){
	}
	
	@Test
	public void testKruskal(){
		
		Kruska kruska = new Kruska(g);
		kruska.createSpanningTree();
		assertTrue("Kantengewicht == 27", (int)kruska.getEdgeWeightSum()==27);
		
	}
	
	@Test
	public void testPrimFibonacci(){
		
		PrimFibonacciJGraphT prim = new PrimFibonacciJGraphT(g,"a");
		prim.createSpanningTree();
		assertTrue("Kantengewicht == 27", (int)prim.getEdgeWeightSum()==27);
		
	}
	
	@Test
	public void testPrimPriorityQueue(){
		
		Prim prim = new Prim(g, "a");
		prim.createSpanningTree();
		assertTrue("Kantengewicht == 27", (int)prim.getEdgeWeightSum()==27);
		
	}	
	
	protected void setupGraphG4() {
		GraphParser gp = new GraphParser("gka4.gka");

		GraphCreater gc = new GraphCreater(gp.getGraphSetup());
		gc.createGraph();

		// add the JGraphT graph to the JGraph adapter
		this.g = gc.getGraph();
	}
	
	public Graph<Node, DefaultWeightedEdge> createNGraph(
			int vertices, int start, int target) {
		// creates a graph with 20 vertices
		this.creater = new GraphNCreater(vertices, start, target);
		return creater.getGraph();
	}
	
	private String createWayString(ArrayList<Node> route){
		String way = "";
		for (int i = 0; i < route.size(); i++) {
			way+= route.get(i).name;
		}
		return way;
	}
}
